import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)
import Login from '../views/login/index.vue'
import Layout from '../views/layout/index'
import Home from '@/views/home'
import Articles from '@/views/articles'
import Pictures from '@/views/pictures'
import NotFound from '@/views/notfound'
import Settings from '@/views/settings'
const routes = [
  { path: '/login', component: Login },
  { path :'/layout', component : Layout,children : [
    {path : '/home',component :Home},
    {path : '/articles', component : Articles},
    {path : '/pictures',component : Pictures},
    {path : '/settings', component : Settings},
    { path: '/*', component: NotFound } 
  ]},
  
]

import {getToken} from '@/utils/token.js'



const router = new VueRouter({
  routes,
})
router.beforeEach((to,from,next)=> {
  if (to.path === '/login' || getToken()) {
     next()
  } else {
    next('/login')
  }
})

export default router
